package cn.xaut.双周赛.m44;

import java.util.ArrayList;
import java.util.List;

/**
 * 1732. 找到最高海拔
 */
public class demo1732 {

    public int largestAltitude(int[] gain) {

        List<Integer> list = new ArrayList<>();
        list.add(0);
        int i = 0, max = 0;
        for (int x : gain) {
            int h = list.get(i++) + x;
            list.add(h);
            max = Math.max(max, h);
        }

        return max;
    }

    public int largestAltitude2(int[] gain) {

        int h = 0, max = 0;
        for (int x : gain) {
            h += x;
            max = Math.max(max, h);
        }
        return max;
    }


        public static void main(String[] args) {

        System.out.println(new demo1732().largestAltitude2(new int[]{-5, 1, 5, 0, -7}));
        System.out.println(new demo1732().largestAltitude2(new int[]{-4, -3, -2, -1, 4, 3, 2}));
    }
}
